package com.piz.web.user;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.piz.model.UserContact;


@Component("contactValidator")
public class ContactValidator implements Validator {

	public boolean supports(Class<?> klass) {
		return UserContact.class.isAssignableFrom(klass);
	}

	public void validate(Object target, Errors errors) {
		UserContact contact = (UserContact) target;
		
		/*if(user!=null && user.getRegisterAs()!=null && user.getRegisterAs().equalsIgnoreCase("Company"))
		{
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "designation", "errorCode", "Designation must not be Empty");
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "companyName", "errorCode", "Company Name must not be Empty");
		}*/
		
		if(contact != null){
			String mobile =  contact.getPhoneMobile();
			String landline = contact.getPhoneLandline();
			if((mobile == null || mobile == "") && (landline == null || landline == ""))
			{
				errors.rejectValue("phoneMobile","","At least one phone number must be enter");
			}
		}
		
	}

}
